<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">

<head>
    <th:block th:include="common/common_head :: commonHeader('资质证书列表')"/>
    <link rel="stylesheet" th:href="@{/static/js/plugins/jquery-layout/jquery.layout-latest.css}">
</head>

<body class="gray-bg">

<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 search-condition">
            <form id="certificateForm" th:action="@{/vendorCertificate/list}" class="form-inline">
                <!-- <input type="hidden" name="deptId" id="deptId"/> -->
                <div class="select-list">
                    <ul>
                        <li class="col-sm-3">
                            <label style="width: 120px">供应商名称：</label>
                            <input type="text" name="vendorName" />
                        </li>
                        <li class="col-sm-3">
                            <label style="width: 120px">证书有效期(始)：</label>
                            <input type="text" id="validityPeriodRise" name="validityPeriodRise" />
                        </li>
                        <li class="col-sm-3">
                            <label style="width: 120px">证书有效期(止)：</label>
                            <input type="text" id="validityPeriodStop" name="validityPeriodStop"/>
                        </li>
                        <li class="col-sm-3">
                            <label style="width: 120px">供应商编码：</label>
                            <input type="text" name="sapCode"/>
                        </li>
                        <li>
                            <button id="certificateSearchBtn" type="button" class="btn btn-primary btn-rounded btn-sm"><i class="fa fa-search"></i>&nbsp;搜索</button>
                            <button class="btn btn-warning btn-rounded btn-sm" type="reset"><i class="fa fa-eraser"></i>&nbsp;重置</button>
                            <button id="certificateAdvancedSearch" type="button" class="btn btn-primary btn-rounded btn-sm" style="display: none"><i class="fa fa-caret-down"></i>&nbsp;高级搜索</button>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        
        <div class="col-sm-12 search-condition titleInfoBar" id="titleInfoBar">
        	<span></span>
        	<div class="titleInfoBarCloseBtn" title="关闭" onclick="closeTitleInfoBar(this)">&times;</div>
        </div>
        
        <div class="col-sm-12 select-info">
            <div class="col-sm-12 select-info">
            <div class="btn-group hidden-xs toolbar" id="certificateToolBar" role="group">
               <!-- <a class="btn btn-outline btn-success btn-rounded" onclick="toVendorCertificate()"
                   shiro:hasPermission="vendor:save">
                    <i class="fa fa-plus"></i> 新增
                </a>-->
                <!--<a class="btn btn-outline btn-success btn-rounded" onclick="toEditVendorCertificate()">
                    <i class="fa fa-edit"></i> 编辑
                </a>-->
                <!-- <a class="btn btn-outline btn-danger btn-rounded" onclick="deleteUser()">
                    <i class="fa fa-remove"></i> 删除
                </a> -->
            </div>
            <table id="certificate"></table>
        </div>
    </div>
  </div>
</div>
<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<script type="text/javascript" th:src="@{/static/js/plugins/jquery-layout/jquery.layout-latest.js}"></script>
<!-- Page-Level Scripts -->
<script type="text/javascript">
    //面向对象
    var searcherBS = Searcher.createBS('#certificate',
        [
            {checkbox: true},
            {title: "供应商编码 ",field:"vendorSapCode",sortable:true},
            {title: '供应商',field:"vendorName", visible: true},
            /*{title: "供应商SRM编码", field:"vendorSrmCode"},*/
            {title: "证书",field:"certificationQualification",sortable:true},
            {title: "体系证书有效期起",field:"validityPeriodRise",sortable:true},
            {title: "体系证书有效期止",field:"validityPeriodStop",sortable:true,
            	formatter : function (value, row, index) {
                    if (value != undefined && value != null && DATE_REG.test(value)) {
                        var apDays = apartNow(value);
            			if(apDays < 0) {//已经过期，亮红灯
            				return "<img src='" + ctxPath + "/img/light/red.png' width='20px' style='margin-right:5px' />" + value;
            			} else if(apDays < 30) {//再过一个月就过期，亮黄灯
            				return "<img src='" + ctxPath + "/img/light/yellow.png' width='20px' style='margin-right:5px' />" + value;
            			} else {//还早着呢，亮绿灯
            				return "<img src='" + ctxPath + "/img/light/green.png' width='20px' style='margin-right:5px' />" + value;
            			}
            		}
            		return value;
            	}
            },
            {title: "操作",field:"fileUrl",formatter : function (value, row, index) {
            	return '<a href="#" onClick="dowloadFileById(\''+row.pkId+'\')">下载</a>';
            	}
            }
        ]
    );
    
    /**
     * 查询数据
     */
    function refresh() {
    	searcherBS.refresh();
    }
    
    $(function () {
        // 初始化时间插件
        laydate.render({elem: '#validityPeriodRise'});
        laydate.render({elem: '#validityPeriodStop'});
        queryTitleInfo();
    });
    
    /**
    * 查询证书有效期信息作为title显示
    */
    function queryTitleInfo() {
        Page.ajaxGET(ctxPath + "/vendorCertificate/groupExpirDate", null, function (res) {
            var result = res.result;
            var text = "总计证书" + result[0] + "份&nbsp;/&nbsp;其中正常"+result[1]+"份&nbsp;/&nbsp;已过期"+result[3]+"份&nbsp;/&nbsp;即将过期"+result[2]+"份";
            showTitleInfoBar($("#titleInfoBar"), text);
        });
    }
    
    /**
     * 跳转至新增页
     */
    function toVendorCertificate() {
        var index=Dialog.openUrl("新增供应商证书", ctxPath + '/modules/certificate/certificate_add.html',{area : ['900px','700px'],
            maxmin: true,
            end: function() {}
        });
        layer.full(index);
    }
    
    //编辑对应供应商下的附件信息
    function toEditVendorCertificate() {
    	var rowDatas = searcherBS.getSelectedRows("pkId");
        if (rowDatas.length != 1) {
            Dialog.errorMsg("请选择一行进行编辑");
            return;
        }
		var index = Dialog.openUrl("编辑供应商证书", ctxPath + '/vendorCertificate/toEdit/'+rowDatas,
		    {area : ['900px','700px'],
			  maxmin: true,
		      end: function () {}
		    });
		layer.full(index);
    }

    /**
     **根据id下载报告文件
     **
     **/
    function dowloadFileById(id) {
        window.location.href=ctxPath + "/vendorCertificate/downloadFileById?id="+id;
    }

</script>
</body>
</html>